package com.elong.businesstravel.modules.init.adapter;

import java.util.HashMap;
import java.util.List;

import com.android.support.jhf.utils.ScreenUtils;
import com.android.support.jhf.utils.ToolUtils;
import com.elong.businesstravel.R;

import android.app.Activity;
import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout.LayoutParams;

/**
 * 引导页
 * 
 * @author lenovo
 * 
 */
public class GuideAdapter extends PagerAdapter {

	private ViewPager mViewPager;
	private Context mContext;
	private int[] mImageIds;
	private int mScreenHeight=0;

	public GuideAdapter(Context context, int[] imageIds, ViewPager viewPager) {
		mContext = context;
		mImageIds = imageIds;
		mViewPager = viewPager;
		mScreenHeight = ScreenUtils.getScreenBounds(mContext)[1];
	}

	@Override
	public Object instantiateItem(View container, final int position) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.adapter_guide, null);

		ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
		imageView.setImageResource(mImageIds[position]);
		if(mScreenHeight <= 800){
//			LayoutParams layoutParams = new LayoutParams(, );
			LayoutParams layoutParams = (LayoutParams) imageView.getLayoutParams();
			layoutParams.width = ToolUtils.dipToPx(mContext, 221);
			layoutParams.height = ToolUtils.dipToPx(mContext, 412);
			imageView.setLayoutParams(layoutParams);
		}
		
		((ViewPager) container).addView(view);

		return view;
	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		((ViewPager) container).removeView((View) object);
	}

	@Override
	public void startUpdate(View container) {
		// Log.d(TAG, "startUpdate");
	}

	@Override
	public void finishUpdate(View container) {
		// Log.d(TAG, "finishUpdate");
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		// Log.d(TAG, "isViewFromObject");
		return view == object;
	}

	@Override
	public Parcelable saveState() {
		// Log.d(TAG, "saveState");
		return null;
	}

	@Override
	public void restoreState(Parcelable state, ClassLoader loader) {
		// Log.d(TAG, "restoreState");
	}

	@Override
	public int getCount() {
		return mImageIds.length;
	}

}
